package com.ruoyi.system.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class ByThreadPoolConfig {

    /**
     * 处理文档导入任务使用的线程池
     */
    @Bean(name = "exportThreadPoolTaskExecutor")
    public ThreadPoolTaskExecutor exportThreadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(500);
        executor.setAllowCoreThreadTimeOut(false);
        executor.setKeepAliveSeconds(1200);
        executor.setThreadNamePrefix("export-task");
        executor.setRejectedExecutionHandler(new RejectedExecutionHandler());
        executor.initialize();
        return executor;
    }

    /**
     * 处理文档导入前置程序使用的线程池
     */
    @Bean(name = "importThreadPoolTaskExecutor")
    public ThreadPoolTaskExecutor importPostThreadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(0);
        executor.setMaxPoolSize(1);
        executor.setQueueCapacity(200);
        executor.setAllowCoreThreadTimeOut(false);
        executor.setKeepAliveSeconds(3600);
        executor.setThreadNamePrefix("import-task");
        executor.setRejectedExecutionHandler(new RejectedExecutionHandler());
        executor.initialize();
        return executor;
    }



}
